<template>
  <div class="loginhome" style="overflow: auto">
    <!-- 头部 -->
    <div class="loginheader">
      <span
        class="el-icon-caret-left"
        @click="goback"
        style="cursor: pointer"
      ></span>
      动态
    </div>

    <!-- 头像加动态区域 -->
    <ul v-infinite-scroll="load">
      <li v-for="(item, index) in newArr" :key="index" class="listy">
        <div class="commentsty">
          <div class="imgdiv">
            <img :src="item.user.avatarUrl" class="imgsty" />
          </div>
          <div class="wenzi">
            {{ item.user.nickname }} 分享单曲： <br />{{
              item.showTime | dateFormat
            }}
          </div>
        </div>
        <!-- 内容图片区域 -->
        <div v-for="(itempic, index) in item.pics" :key="index" class="picdiv">
          <img :src="itempic.originUrl" class="picurl" />
        </div>
        <!-- 内容文字区域 -->
        <div class="contentdiv">{{ item.a.msg }}</div>
        <!-- 歌曲区域 -->
        <div class="songdiv" @click="playsong(item.a.song.id)">
          <div><img :src="item.a.song.img80x80" class="songimgsty" /></div>
          <div class="songwenzi">
            <span class="namesty"> {{ item.a.song.name }}</span>
            <br />
            <span>{{ newName }}</span>
            <span
              v-for="(itemart, index) in item.a.song.artists"
              :key="index"
              class="artsty"
              >{{ itemart.name }}
              <span
                v-if="index < item.a.song.artists.length - 1"
                :istwoname="
                  item.a.song.artists.length !== 1
                    ? (istwoname = '/')
                    : (istwoname = '')
                "
                >{{ istwoname }}</span
              >
            </span>
          </div>
        </div>
      </li>
    </ul>
    <!-- 播放区域 -->

    <div v-for="(item, index) in songurl" :key="index">
      <div class="playing">正在播放</div>
      <div class="audiodiv">
        <audio :src="item.url" controls autoplay></audio>
      </div>
    </div>
    <!-- 页脚区域 -->
    <Footer class="footer" />
  </div>
</template>

<script>
import Footer from "./Footer.vue";
export default {
  components: { Footer },
  data() {
    return {
      msg: [],
      count: 0,
      pics: [],
      newArr: [],
      picsArr: [],
      songurl: [],
      istwoname: "/",
    };
  },
  created() {
    this.getmsg();
  },
  methods: {
    // 播放歌曲
    playsong(id) {
      this.axios
        .get(`/song/url?id=${id}`)
        .then((res) => {
          this.songurl = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    load() {
      this.count += 2;
    },
    // 获取好友动态
    getmsg() {
      this.axios
        .get(`/event?pagesize=30`)
        .then((res) => {
          this.msg = res.data.event;
          this.newArr = this.msg.map(function (item) {
            const a = JSON.parse(item.json);
            return {
              a: a,
              pics: item.pics,
              user: item.user,
              showTime: item.showTime,
            };
          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //   返回按钮返回
    goback() {
      this.$router.go(-1);
    },
  },
};
</script>

<style scoped>
.playing {
  font-size: 20px;
  margin-left: 20px;
  color: red;
}
.audiodiv {
  margin-left: 40px;
  margin-bottom: 20px;
  margin-top: 10px;
}
.footer {
  margin-left: 15px;
}
.artsty {
  font-size: 12px;
}
.songwenzi {
  width: 220px;
  height: 40px;
  margin-left: 10px;
  margin-top: 10px;
  overflow: hidden;
}
.namesty {
  font-weight: 700;
}
.songdiv {
  display: flex;
  width: 300px;
  height: 60px;
  margin-left: 48px;
  background-color: skyblue;
  margin-bottom: 30px;
  cursor: pointer;
}
.songimgsty {
  width: 60px;
  height: 60px;
}
.contentdiv {
  margin-left: 48px;
  margin-bottom: 10px;
  margin-top: 10px;
}
.picurl {
  width: 160px;
  height: 240px;
  margin-left: 48px;
}

.loginheader {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: red;
  border-bottom: red 1px solid;
  height: 30px;
}
.imgsty {
  height: 40px;
  width: 40px;
  border-radius: 20px;
}
.listy {
  margin-top: 10px;
}
.wenzi {
  font-size: 16px;
  color: red;
  margin-left: 10px;
}

.content {
  margin-left: 50px;
  margin-bottom: 20px;
}
.commentsty {
  display: flex;
}
</style>